package com.akcome.apollo.repository;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import com.akcome.apollo.domain.VMiningWorkers;
import com.akcome.apollo.dto.AccountAcceptDto;

/**
 * Repository接口
 *
 * @author wn
 * @version $v: 1.0.0, $time:2017-12-26 08:49:00 Exp $
 */
public interface VMiningWorkersRepository extends JpaRepository<VMiningWorkers,Long>,JpaSpecificationExecutor<VMiningWorkers> {

	int countByPuidAndCointype(Long puid,String cointype);
	
	//@Query(nativeQuery=true,value="select count(*) from v_mining_workers where puid=?1 and accept_5m>?2 and cointype=?3 and updated_at>=?4")
	int countByPuidAndAccept5mGreaterThanAndCointypeAndUpdatedAtGreaterThanEqual(Long puid,Long accept5m,String cointype,Date date);
	
	@Query(nativeQuery=true,value="select cointype,count(*) from v_mining_workers where accept_5m>?1 and updated_at>=?2 group by cointype")
	List<Object> countByActive(Long accept5m,Date date);

	
	@Query("select new com.akcome.apollo.dto.AccountAcceptDto(SUM(accept1m),SUM(accept5m),SUM(accept15m),SUM(accept1h)) from VMiningWorkers where puid=?1 and cointype=?2")
	AccountAcceptDto sumAcceptBypuid(Long puid,String cointype);
}
